package com.threesome.memos.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.threesome.memos.R;
import com.threesome.memos.db.Memo;

public class MemosAdapter extends CursorAdapter {
	private final LayoutInflater mFactory;
	public MemosAdapter(Context context, Cursor cursor) {
		super(context, cursor);
		mFactory = LayoutInflater.from(context);
	}
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView memoContent = (TextView)view.findViewById(R.id.memo_content);
		TextView memoTrigger = (TextView)view.findViewById(R.id.memo_trigger);

		String content = cursor.getString(cursor.getColumnIndex(Memo.Columns.MEMO_CONTENT));
		if(content != null && content.length() > 0) {
			memoContent.setText(content);
		}
		String trigger = cursor.getString(cursor.getColumnIndex(Memo.Columns.MEMO_TRIGGER));
		if(trigger != null && trigger.length() > 0) {
			memoTrigger.setText(trigger);
		}
	}
	
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return mFactory.inflate(R.layout.memo_item, parent, false);
	}
}
